package com.dhc.appbusinessfrm.task;

/**
 * Created by xy on 2015/6/18.
 */
public abstract class AsyncTask<T> implements CallableTask {
    private TaskLocker<T> locker = new TaskLocker<T>();

    public abstract void beforeExecute();

    public abstract void onExecute(TaskLocker<T> locker);

    public abstract void afterExecute();

    public TaskLocker<T> getLocker() {
        return locker;
    }

    @Override
    public T call() throws Exception {
        try {
            beforeExecute();
            synchronized (locker) {
                onExecute(locker);
                locker.wait();
            }
        } catch (Exception ex) {

        } finally {
            afterExecute();
        }

        return locker.getResult();
    }
}
